<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .title{
            line-height: 40px;
            font-weight: 700;
        }

        .title span{
            color: lightskyblue;
        }

        .data {
            padding: 10px;
        }

        .data .search {
            margin-top: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .data .search input {
            width: 250px;
            height: 35px;
            border-radius: 15px;
            border: 0;
            background-color: rgb(239, 237, 237);
            padding-left: 20px;
        }

        .data .search span {
            color: lightskyblue;
        }

        .data .box {
            margin-top: 20px;
        }

        .data .box h4 span {
            color: gray;
            float: right;
            font-size: 12px;
            font-weight: 400;
        }

        .data .box .list {
            font-size: 12px;
            margin-top: 5px;
            width: 100%;
        }

        .data .box .list .find {
            padding: 5px;
            background-color: rgb(239, 237, 237);
            display: inline-block;
            margin: 5px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="data">
            <div class="title"><span>&lt;</span> 搜索</div>
            <div class="search">
                <input type="text" placeholder="搜索商家、商品名称" v-model="inputText"><span @click="search">搜索</span>
            </div>
            <div class="box">
                <h4>历史搜索 <span @click="del">🚽</span></h4>
                <div class="list">
                    <div class="find" v-for="(item,index) in findlist" :key="index">{{ item.name }}</div>
                </div>
            </div>
            <div class="box">
                <h4>搜索发现</h4>
                <div class="list">
                    <span class="find" v-for="(item,index) in searchlist" :key="index">{{ item.name }}</span>
                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v = new Vue({
        el: '#app',
        data: {
            inputText: '',
            findlist: [],
            searchlist: [
                { name: '麻辣烫' },
                { name: '麻辣米线' },
                { name: '汉堡' },
                { name: '烧烤' },
                { name: '日料' },
                { name: '火锅' },
                { name: '韩餐' },
                { name: '砂锅' },
                { name: '酒店' },
            ]

        },
        methods: {
            search() {
                if (this.inputText) {
                    var obj = { name: this.inputText };
                    this.findlist.push(obj);
                }
                this.inputText = '';
            },
            del() {
                this.findlist = [];
            }
        }
    })
</script>